/*
 * CadastrodeTipodeProduto.java
 *
 * Created on 26 de Novembro de 2008, 19:26
 */
package br.faimg.pomar.visual;

import br.faimg.pomar.controle.componentevisual.TableTipodeErro;
import javax.swing.JTable;
import javax.swing.table.TableModel;

/**
 *
 * @author  diogo
 */
public class CadastrodeTipodeErro extends javax.swing.JInternalFrame {

    /** Creates new form CadastrodeTipodeProduto */
    public CadastrodeTipodeErro() {
        initComponents();
        updateTable();
        alterarjButton2.setEnabled(false);
        

    }

    private void updateTable() {
        //Lista os itens cadastrados no banco na tablela
        tabelaTipojTable.setModel(new JTable(
                new TableTipodeErro().getTableModel()).getModel());
    }
    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jPanel1 = new javax.swing.JPanel();
        jSeparator1 = new javax.swing.JSeparator();
        tabelaScrollPane = new javax.swing.JScrollPane();
        tabelaTipojTable = new javax.swing.JTable();
        incluirjButton1 = new javax.swing.JButton();
        alterarjButton2 = new javax.swing.JButton();
        cancelarjButton3 = new javax.swing.JButton();

        setTitle("Cadastro de tipo de erro");

        jPanel1.setLayout(new org.netbeans.lib.awtextra.AbsoluteLayout());
        jPanel1.add(jSeparator1, new org.netbeans.lib.awtextra.AbsoluteConstraints(10, 310, 620, 10));

        tabelaScrollPane.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                tabelaScrollPaneMouseClicked(evt);
            }
        });

        tabelaTipojTable.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {
                {null, null},
                {null, null},
                {null, null},
                {null, null}
            },
            new String [] {
                "Código", "Descrição"
            }
        ));
        tabelaTipojTable.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                tabelaTipojTableMouseClicked(evt);
            }
        });
        tabelaScrollPane.setViewportView(tabelaTipojTable);
        tabelaTipojTable.getColumnModel().getColumn(0).setMinWidth(60);
        tabelaTipojTable.getColumnModel().getColumn(0).setPreferredWidth(60);
        tabelaTipojTable.getColumnModel().getColumn(0).setMaxWidth(60);

        jPanel1.add(tabelaScrollPane, new org.netbeans.lib.awtextra.AbsoluteConstraints(10, 10, 630, 290));

        incluirjButton1.setText("Incluir");
        incluirjButton1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                incluirjButton1ActionPerformed(evt);
            }
        });
        jPanel1.add(incluirjButton1, new org.netbeans.lib.awtextra.AbsoluteConstraints(350, 330, 90, -1));

        alterarjButton2.setText("Alterar");
        alterarjButton2.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                alterarjButton2ActionPerformed(evt);
            }
        });
        jPanel1.add(alterarjButton2, new org.netbeans.lib.awtextra.AbsoluteConstraints(450, 330, 90, -1));

        cancelarjButton3.setText("Cancelar");
        cancelarjButton3.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                cancelarjButton3ActionPerformed(evt);
            }
        });
        jPanel1.add(cancelarjButton3, new org.netbeans.lib.awtextra.AbsoluteConstraints(550, 330, 80, -1));

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, 634, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, 378, Short.MAX_VALUE)
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

private void jPanel1KeyPressed(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_jPanel1KeyPressed
// TODO add your handling code here:
}//GEN-LAST:event_jPanel1KeyPressed

private void alterarButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_alterarButtonActionPerformed
/*
    // TODO add your handling code here:
if(codigoTextField.getText().equals("")||descricaoTextField.getText().equals("")){
    erroEntradaDados.setText(" Entrada Inválida!   Existem campos não preenchidos.");
}
else{
    TipodeErroBusinessDelegate delegate = new TipodeErroBusinessDelegate();
    delegate.update(codigoTextField.getText(), descricaoTextField.getText());
    updateTable();

    //Limpa os combos apos a insercao para permitir nova insercao
    codigoTextField.setText("");
    codigoTextField.setEnabled(true);
    descricaoTextField.setText("");
    cancelarButton.setText("Cancelar");
    okButton.setEnabled(true);
    }
 * */
}//GEN-LAST:event_alterarButtonActionPerformed

private void tabelaTipojTableMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_tabelaTipojTableMouseClicked

    alterarjButton2.setEnabled(true);

}//GEN-LAST:event_tabelaTipojTableMouseClicked
/*
private void descricaoTextFieldKeyPressed(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_descricaoTextFieldKeyPressed
// TODO add your handling code here:
    cancelarButton.setText("Limpar");
    erroEntradaDados.setText("");
    
}//GEN-LAST:event_descricaoTextFieldKeyPressed
*/
private void codigoTextFieldKeyPressed(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_codigoTextFieldKeyPressed
// TODO add your handling code here:
   // cancelarButton.setText("Limpar");
   // erroEntradaDados.setText("");
}//GEN-LAST:event_codigoTextFieldKeyPressed

private void incluirjButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_incluirjButton1ActionPerformed
// TODO add your handling code here:
    
 CadastrodeErroInclusao view = new CadastrodeErroInclusao();
 view.setModal(true);
 view.setVisible(true);
 view.setResizable(true);
 
 updateTable();
}//GEN-LAST:event_incluirjButton1ActionPerformed

private void alterarjButton2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_alterarjButton2ActionPerformed
    
    TableModel tableModel = tabelaTipojTable.getModel();
    int linha = tabelaTipojTable.getSelectedRow();
     
    CadastrodeErroInclusao view = new CadastrodeErroInclusao((String)tableModel.getValueAt(linha,0), (String)tableModel.getValueAt(linha,1));

    view.setModal(true);
    view.setResizable(false);
    view.setVisible(true);
    

    updateTable();
}//GEN-LAST:event_alterarjButton2ActionPerformed

private void cancelarjButton3ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_cancelarjButton3ActionPerformed
    this.setVisible(isIcon);
   
}//GEN-LAST:event_cancelarjButton3ActionPerformed

private void tabelaScrollPaneMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_tabelaScrollPaneMouseClicked
        
    if (tabelaTipojTable.getSelectedRow() >= 0){
            alterarjButton2.setEnabled(true);
        } else {
            alterarjButton2.setEnabled(false);
            
        }
}//GEN-LAST:event_tabelaScrollPaneMouseClicked


    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton alterarjButton2;
    private javax.swing.JButton cancelarjButton3;
    private javax.swing.JButton incluirjButton1;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JSeparator jSeparator1;
    private javax.swing.JScrollPane tabelaScrollPane;
    private javax.swing.JTable tabelaTipojTable;
    // End of variables declaration//GEN-END:variables
}
